package org.example.controller;

import lombok.RequiredArgsConstructor;
import org.example.domain.ResponseResult;
import org.example.domain.dto.SpotListDto;
import org.example.domain.entity.Spot;
import org.example.enums.AppHttpCodeEnum;
import org.example.exception.SystemException;
import org.example.service.SpotService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spot")
@RequiredArgsConstructor
public class SpotController {

    private final SpotService spotService;

    @PostMapping("/addSpot")
    public ResponseResult addSpot(@RequestBody Spot spot){

        if(!StringUtils.hasText(spot.getSpotName())){
            throw new SystemException(AppHttpCodeEnum.NOT_SPOT_NAME_ERROR);
        }

        return spotService.addSpot(spot);
    }


    @PostMapping("/spotList")
    public ResponseResult spotList(@RequestBody SpotListDto spotListDto){

        return spotService.spotList(spotListDto);
    }

    @PutMapping("/updateSpot")
    public ResponseResult updateSpot(@RequestBody Spot spot){
        return spotService.updateSpot(spot);
    }
}
